package xframe.util.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import xecure.servlet.*;

public class XecureFilter implements Filter{

    public XecureFilter(){}

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException{
    	
    	 XecureServlet xservlet = null;
    	 String orgUrl = "";
    	 request.setCharacterEncoding("euc-kr");
    	 
        if ( request.getParameter("q") != null ){
        	System.out.println("In Secret..");
            try{
	           	 xservlet = new XecureServlet((HttpServletRequest)request, (HttpServletResponse)response);
	             orgUrl = xservlet.request.getRequestURI();
	             request.getRequestDispatcher(orgUrl+"?command="+xservlet.request.getParameter("command")).forward(request, response);
            }catch(Exception e){          }
		} else {
            chain.doFilter(request, response);
        } 
    }

    public void destroy(){}

    public void init(FilterConfig arg0) throws ServletException{}
}
